<template>
    <div class="logindiv">
        <div class="tool-box"></div>
        <div class="head-box">
            <div class="comwid clearfix">
                <div class="head-logo lf">
                    <a class="titlename" href="javaScript:;">
                        <span class="titlenamea">内蒙古自治区测绘地理信息中心</span>
                        <span class="titlenameb">卫星变化图斑管理</span>
                    </a>
                </div>
            </div>
        </div>
        <div class="nav-box"></div>
        <div class="loginform">
            <div class="loginformb">
                <a-form :model="form"  @submit="handleSubmit" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
                    <a-form-item label="手机号">
                        <!-- 'Please input your username!' -->
                        <a-input  v-model:value="form.username"/>
                    </a-form-item>
                    <a-form-item label="密码">
                        <!-- Please input your password! -->
                        <a-input-password v-model:value="form.password" />
                    </a-form-item>
                    <a-form-item :wrapper-col="{ span: 16, offset: 4 }" >
                        <a-button id="login_btn" type="primary" html-type="submit" style="width:100%" >登陆</a-button>
                    </a-form-item>
                </a-form>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                form: {
                    username:"",
                    password:"",
                },
            };
        },
        mounted(){
            document.onkeydown = () => {
                let _key = window.event.keyCode;
                if (_key === 13) {
                    this.handleSubmit();
                }
            }
            document.getElementById("login_btn").focus()
            // this.$user.read_user().then((_true)=>{
            //     if(_true==true){
            //         this.$router.push("/mytask");
            //     }
            // })
        },
        methods: {
            async handleSubmit(e) {
                if(this.form.username && this.form.password){
                    this.login_user();
                }
            },
            login_user() {
                this.$common_apis.axios_post('/login_user?',{
                    username: this.form.username,
                    password: this.form.password
                }).then(async (result) => {
                    if(result){
                        this.$user.set_token(result)
                        await this.$user.write_user()
                        this.$router.push("/mytask");
                    }
                })  
            },
        },
    }
</script>
<style>
    
</style>